package com.qf.smsplatform.search.mq;

import com.qf.smsplatform.common.constants.RabbitMQConstants;
import com.qf.smsplatform.common.model.StandardSubmit;
import com.qf.smsplatform.search.service.SearchService;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @Author: LeeRui
 * 2021/2/2 下午 7:44
 * 监听日志队列，将消息中submit对象存到ES
 **/
@Component
public class SendLogListener {

    @Autowired
    private SearchService searchService;

    @RabbitListener(queues = RabbitMQConstants.TOPIC_SMS_SEND_LOG)
    public void logConsumer(StandardSubmit standardSubmit, Channel channel, Message message) throws IOException {
        //保存submit对象到ES
        searchService.saveLog(standardSubmit);
        //手动ACK
        channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
    }
}
